package com.aaa.service.impl;

import com.aaa.entity.Facility;
import com.aaa.entity.Role;
import com.aaa.mapper.FaciltyMapper;
import com.aaa.service.FacilityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("facilityServiceImpl")
public class FacilityServiceImpl implements FacilityService {

    @Resource
    private FaciltyMapper faciltyMapper;


    @Override
    public List<Facility> findbyid() {
        return faciltyMapper.findbyid();
    }


    @Override
    public Integer facilityadd(Integer id, Integer[] arr) {
        faciltyMapper.delFaclilityById(id);
        if (arr.length == 0) {
            System.out.println(1);
            arr = null;
            return null;
        }
        return faciltyMapper.add(id, arr);
    }

    @Override
    public List<Integer> findFacilityById(Integer id) {
        return faciltyMapper.findFacilityById(id);
    }

    /**
     * 分页查询
     *
     * @param fname    模糊查询动态值
     * @param pageNum  当前页
     * @param pageSize 每页几条数据
     * @return 返回数据
     */
    @Override
    public PageInfo<Facility> query(String fname, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);//将当前页和每页的数量放到PageHelper
        List<Facility> facilities = faciltyMapper.query(fname);//接受前台返回结果集
        PageInfo<Facility> pageInfo = new PageInfo<>(facilities);//用PageInfo分页处理数据
        return pageInfo; //返回结果
    }

    /**
     * 处理查询的数据
     *
     * @param fname 根据设施名称
     * @return 返回数据
     */
    @Override
    public List<Map<String, Object>> findByFname(Integer id,String fname) {
        return faciltyMapper.findByFname(id,fname);
    }

    /**
     * 根据id查询出的数据处理
     *
     * @param id 对象
     * @return 返回数据
     */
    @Override
    public Facility findById(Integer id) {
        return faciltyMapper.findById(id);
    }

    /**
     * 处理添加的数据
     *
     * @param fname 要添加的字段
     * @return 返回数据
     */
    @Override
    public Integer newly(String fname) {
        return faciltyMapper.newly(fname);
    }

    /**
     * 房间设施数据处理
     *
     * @param facility 房间设施对象
     * @return 返回数据
     */
    @Override
    public Integer edit(Facility facility) {
        return faciltyMapper.edit(facility);
    }

}
